﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections.Specialized;
using System.Web;

namespace Standard
{
    /// <summary>
    /// 搜索枚举
    /// </summary>
    public enum SearchRecordKeys
    {
        /// <summary>
        /// 搜索关键字
        /// </summary>
        KeyWord,
        /// <summary>
        /// 模块
        /// </summary>
        Module,
    }

    /// <summary>
    /// 用户信息
    /// </summary>
    public class SearchRecordImplement
    {
        #region Consts and Fields
        /// <summary>
        /// Session键值
        /// </summary>
        internal const string SessionKey = "Standar_SearchRecord";
        /// <summary>
        /// cookies 分隔符号
        /// </summary>
        internal static char[] SPCHAR = { ',' };
        #endregion

        #region Properties
        /// <summary>
        /// 搜索关键字
        /// </summary>
        public ISearchRecord[] SearchRecordArray
        {
            get
            {
                return this.GetSearchRecordArray();
            }
        }
        internal ISearchRecord[] GetSearchRecordArray()
        {
            var httpCookie = HttpContext.Current.Request.Cookies[ClientHelper.SearchRecordName];
            if (httpCookie == null || string.IsNullOrEmpty(httpCookie.Value)) { return null; }
            string[] keys = httpCookie.Values.AllKeys.Where(item => !string.IsNullOrEmpty(item)).ToArray();
            ISearchRecord[] searchRecord = new SearchRecord[keys.Length];
            string userID = ClientHelper.Current.HasUserInfo ? ClientHelper.Current.UserInfo.UserID : null;
            for (int index = 0; index < keys.Length; index++)
            {
                if (searchRecord[index] == null) { searchRecord[index] = new SearchRecord(null, 0); }
                searchRecord[index].KeyWord = keys[index];
                searchRecord[index].Module = int.Parse(httpCookie.Values[keys[index]]);
            }
            return searchRecord;
        }


        #endregion

    }

    ;
}
